1. Field of the Invention
The present invention relates to a method of generating a CRC (Cyclic Redundancy Check) code, and more particularly to a CRC code generating method which is capable of generating a desired CRC code by changing a portion of data.
2. Description of the Related Art
In serial communications performed over cables, a voltage level may possibly suffer a drift due to a low-frequency component when a succession of data having the same voltage level occurs. To prevent such a drift, there is employed a technique called bit stuffing which, when a succession of “1s” or “0s” occurs in data to be transmitted, inserts a bit having a logic value that is opposite to the logic values in succession. For example, according to a USB data packet format that is used for a USB (Universal Serial Bus) which is known as a typical serial transmission application, it is stipulated that if a succession of seven “1s” occurs in data to be transmitted, then “0” is to be inserted after the sixth “1” in the data to be transmitted to the bus. It is also stipulated as an exception for the above provision that if a succession of seven “1s” occurs in data transmitted over a bus, then it represents an EOF (End Of Frame).
In serial communications, a CRC (Cyclic Redundancy Check) code is used to detect an error that may be caused in the transmission of data. For serial communications, there is generally used a frame format comprising a CRC field and an EOF in succession at the end of a frame which is made up of a bunch of data flowing through a network.
For conducting a transmission and reception test using a CRC code, as described in paragraph [0003] to [0006]of Japanese Patent Laid-open Application No. 2001-244820 (JP P2001-244820A), a predetermined generator polynomial is used on data in each frame unit on the transmission side to calculate a CRC code, and the calculated CRC code is added to the data to be transmitted and then transmitted. On the reception side, the received data is divided using the same generator polynomial as the one used on the transmission side, and if a residue is produced, then it is determined that an error has occurred in the transmitted data.
For conducting a test to determine whether a packet is properly transmitted and received between a transmitting apparatus and a receiving apparatus or not, it is preferable if an arbitrary code can be set in a CRC field. For performing face-to-face communications (bidirectional communications) with a product developed by a different maker (manufacturer), it is necessary to generate an arbitrary CRC code for the purpose of confirming whether proper functions of the both parties are achieved or not.
FIG. 1 shows an exemplary arrangement of a serial communication system. As shown in FIG. 1, transmitting apparatus 1 and receiving apparatus 8 are connected to each other by transmission path 9. Transmitting apparatus 1 transmits serial transmission data TD to transmission path 9, from which serial transmission data TD is received by receiving apparatus 8.
FIG. 2 shows an example of an arrangement of transmitting apparatus 1. As shown in FIG. 2, transmitting apparatus 1 comprises CPU (central processing unit) 92, memory 93 for storing data therein, and serial transmitting unit 94 for transmitting data from CPU 92 as serial transmission data TD to the transmission path.
FIG. 3A shows, by way of example, an arrangement of a transmission frame which is transmitted as serial transmission data TD. The transmission frame comprises data field 141, CRC field 142 for storing a CRC code which is generated based on the data of data field 141, and EOF field 143 following CRC field 142. In FIG. 3A, the CRC code appended in CRC field 142 represents “0001”. The CRC code will also be hereinafter referred to as “CRC value.”
It is assumed that, as shown in FIG. 3B, the value “0001” of CRC field 142 is replaced with a desired value, e.g., “1011”, and then transmitted. In this case, transmitting apparatus 1 shown in FIG. 2 operates according to an operation sequence represented by a flowchart shown in FIG. 4. In step 201, data is stored in memory 93. In step 202, the data is read from memory 93. In step 203, a CRC value corresponding to the read data is calculated according to a predetermined generator polynomial. Thereafter, in step 204, the calculated CRC value is replaced with a desired CRC value. In step 205, the fields are combined in the order described above, making a frame which is transmitted. When the CRC value is thus replaced, the receiving apparatus detects an unmatched CRC error, which prevents a normal test from being conducted. In a face-to-face test for transmitting and receiving a frame between apparatus which are connected to each other, when a CRC error occurs, an error process immediately follows. Therefore, if the value of the CRC field is simply replaced with a desired value, then it is not possible to confirm a process to be performed after normal transmission and reception of data has been confirmed.
To solve the above problem, there has been employed a process of providing a variable field where data can be changed in a data field and CRC calculations are repeated one by one while changing the data of the variable field until the CRC value becomes a desired value, as shown in FIGS. 5A and 5B. FIG. 5A shows a transmission frame made up of data field 21, CRC field 23, and EOF field 24, data field 21 containing variable field 22. The value of variable field 22 is “0000”, and the value of CRC field 23 is “0001” accordingly. In order to equalize the value of CRC field 23 to “1011” as shown in FIG. 5B, CRC calculations are repeated to search for the value “0101” of variable field 22, and the value that has been searched for is stored in variable field 22.
FIG. 6 is a flowchart of a sequence of such a process of generating a CRC code.
In step 211 shown in FIG. 6, transmitting apparatus 1 sets a variable field value X to “0” in variable field 22. If the variable field length is represented by 4 bits, then the variable field value X is set to “0000” in variable field 22. In step 212, data is stored in memory 93. In step 213, the data is read from memory 93. In step 214, CPU 92 calculates a CRC value corresponding to the read data. In step 215, CPU 92 determines whether the CRC value calculated in step 214 is equal to a desired CRC value or not. If not equal, then control goes to step 216. In step S16, “1” is added to the variable field value X. Then, control returns to step 214. If the calculated CRC value is judged as being equal to the desired CRC value in step 215, then control goes to step 217. In step 217, fields are combined in a predetermined order, producing a frame, and the frame is transmitted.
With the sequence shown in FIG. 6, however, a CRC value has to be recalculated each time the variable field value X is incremented. Consequently, it is highly time-consuming to obtain a frame having a desired CRC value.